package org.libarae.server;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Vector;

import org.libarae.communication.ServerInterface;
import org.libarae.communication.common.*;
import org.libarae.communication.common.User.Permission;
import org.libarae.communication.request.*;
import org.libarae.communication.response.*;

/**
 * @author Tyler Holzer
 * 
 * OperationThread.java -- a part of Libarae
 * 
 * handles incoming socket requests and sends off an appropriate response
 */
public class OperationThread extends Thread {
	
	/**
	 * the Server Interface to send responses, and get the parsed data
	 */
	private ServerInterface sInterface;
	/**
	 * the request object that was parsed out of the socket
	 */
	private Request request; 
	/**
	 * the response to be sent back
	 */
	private Response response; 
	/**
	 * The user associated with the given auth key
	 */
	private User user;
	
	/**
	 * Constructor
	 * 
	 * @param sInterface - ServerInterface interprets data from the socket and generates requests and sends responses
	 */
	public OperationThread(ServerInterface sInterface) {
		this.sInterface=sInterface;
		request=null;
		response =null;
		user=null;
	}
	
	/* 
	 * Overrides Threads run method, generates the response
	 * (non-Javadoc)
	 * @see java.lang.Thread#run()
	 */
	public void run() {
		//Verify valid thread creation
		if(sInterface==null) {
			return;
		}
		
		//Parse out the incoming request
		try {
			request = sInterface.getRequest();
		}
		catch(IOException e) {
			if(Server.config.inDebugMode()) {//DEBUG MESSAGE
				System.out.println("Error reading from Socket");
				e.printStackTrace();
			}
			return;
		}
		catch (Exception e) {
			if(Server.config.inDebugMode()) {//DEBUG MESSAGE
				System.out.println("Error contained in data from Socket");
				e.printStackTrace();
			}
			return;
		}
		
		//Handle Request
		if(request!=null) {
			//if the request isn't a login, ping or new user, check authkey
			if((request.getType()!=Type.LOGIN&&request.getType()!=Type.NEW_USER)&&request.getType()!=Type.SERVER_PING) {
				//Check the AuthKey and get User object
				user=Server.manager.checkAuth(request.getAccessKey());

				if(user==null){
					//the key was not valid, return a bad response
					response=new GenericResponse(Response.STATUS_FAILED_BAD_KEY);
				}
			}
			if(response==null) {
				//handle each request type
				switch(request.getType()) {
					case Type.LOGIN:
						handleLoginRequest();
						break;
					case Type.NEW_USER:
						handleNewUserRequest();
						break;
					case Type.HEART_BEAT:
						handleHeartbeat();
						break;
					case Type.FEATRUED_TAB:
						handleFeatured();
						break;
					case Type.BOOK_SEARCH:
						handleBookSearch();
						break;
					case Type.BOOK_INFO:
						handleBookInfo();
						break;
					case Type.PROFILE_TAB:
						handleProfileTab();
						break;
					case Type.ISBN_LOOKUP:
						handleISBNLookup();
						break;
					case Type.CREATE_BOOK:
						handleBookCreation();
						break;
					case Type.MAILBOX_MESSAGES:
						handleMessages();
						break;
					case Type.LOGOUT:
						handleLogout();
						break;
					case Type.SEND_MESSAGE:
						handleSendMessage();
						break;
					case Type.SERVER_PING:
						handlePing();
						break;
					case Type.ACCOUNT_INFO:
						handleAccountInfo();
						break;
					case Type.ACCOUNT_UPDATE:
						handleAccountUpdate();
						break;
					case Type.MODERATOR_PANEL:
						handleModeratorPanel();
						break;
					case Type.MODERATOR_ACTION:
						handleModeratorAction();
						break;
					case Type.ADMIN_PANEL:
						handleAdminPanel();
						break;
					case Type.ADMIN_ACTION:
						handleAdminAction();
						break;
					case Type.SERVER_INFO:
						handleServerInfo();
						break;
					case Type.CHANGE_MESSAGE_STATUS:
						changeThreadStatus();
						break;
					case Type.PICTURE:
						handlePictureRequest();
						break;
					case Type.GET_THREAD_MESSAGES:
						handleThreadMessages();
						break;
					case Type.EDIT_BOOK:
						handleEditBook();
						break;
					default:
						if(Server.config.inDebugMode())//DEBUG MESSAGE
							System.out.println("Unknown request...");
						response=new GenericResponse(Response.STATUS_FAILED_GENERIC);
						break;
				}
			}
			try {
				if(Server.config.inDebugMode())//DEBUG MESSAGE
					System.out.println("Response sent - Status: "+response.getStatus());
				
				if(request.isWebRequest())
					response.setHtmlHelperMessage(request.getHtmlHelperMessage());
				//send off the response
				sInterface.sendResponse(response);
			}
			catch(Exception e) {
				if(Server.config.inDebugMode()) {//DEBUG MESSAGE
					System.out.println("An error occured while sending a response");
					e.printStackTrace();
				}
				return;
			}
		}
	}
	
	
	/**
	 * parses the request as if it were a LoginRequest, and sets the response appropriately
	 */
	private void handleLoginRequest() {
		//check if server password is required, and check it against the database
		if(Server.config.passwordRequired()) {
			if(((LoginRequest)request).getServerPassword().equals("")) {
				response=new LoginResponse(LoginResponse.STATUS_FALLED_SERVER_REQUIRES_MASTER_PASS);
				return;
			}
			else if(!((LoginRequest)request).getServerPassword().equals(Server.manager.getServerPassword())){
				response=new LoginResponse(LoginResponse.STATUS_FALLED_BAD_SERVER_PASS);
				return;
			}
		}
		//check the provided username and login against those stored in the database
		try {
			ActiveUser user=Server.manager.login(((LoginRequest)request).getUserName(), ((LoginRequest)request).getPassword());
			if(user==null){
				response=new LoginResponse(LoginResponse.STATUS_FAILED_BAD_USER_OR_PASS,"",-1);
			}
			else {
				int unread=Server.manager.unReadMessages(user.getUser().getUID());
				response=new LoginResponse(LoginResponse.STATUS_GOOD,user.getAuthKey(),unread);
			}
		}
		catch(Exception e) {
			if(Server.config.inDebugMode())//DEBUG MESSAGE
				e.printStackTrace();
			response=new LoginResponse(LoginResponse.STATUS_FAILED_GENERIC,"",-1);
		}
	}
	
	/**
	 * parse the request as if it were a newUserRequest and set the response appropriately 
	 */
	private void handleNewUserRequest() {
		//check server password
		if(Server.config.passwordRequired()) {
			if(((NewUserRequest)request).getServerPassword().equals("")) {
				response=new NewUserResponse(NewUserResponse.STATUS_FAILED_SERVER_REQUIRES_MASTER_PASS);
				return;
			}
			else if(!((NewUserRequest)request).getServerPassword().equals(Server.manager.getServerPassword())){
				response=new NewUserResponse(NewUserResponse.STATUS_FALLED_BAD_SERVER_PASS);
				return;
			}
		}
		//Attempt to create a new user
		try {
			String auth=Server.manager.addNewUser(((NewUserRequest)request).getUser());
			if(auth==null){
				response=new NewUserResponse(NewUserResponse.STATUS_FAILED_USER_EXISTS,"");
			}
			else {
				response=new NewUserResponse(NewUserResponse.STATUS_GOOD,auth);
			}
		}
		catch(Exception e) {
			if(Server.config.inDebugMode())//DEBUG MESSAGE
				e.printStackTrace();
			response=new NewUserResponse(NewUserResponse.STATUS_FAILED_GENERIC,"");
		}
	}
	
	/**
	 * handles heartbeat requests and set the response appropriately 
	 */
	private void handleHeartbeat() {
		int unread=Server.manager.unReadMessages(user.getUID());
		if(unread!=-1)//if unread returned an error, send fail
			response=new HeartBeatResponse(Response.STATUS_GOOD,unread);
		else
			response=new HeartBeatResponse(Response.STATUS_FAILED_GENERIC,0);
	}
	
	/**
	 * handles the featured tab request and set the response appropriately 
	 */
	private void handleFeatured() {
		ArrayList<Book> recent=Server.manager.recentBooks(5); // get the five most recently added books
		ArrayList<Book> active=Server.manager.activeBooks(5); //get the five books with the most checkouts
		if(recent==null || active == null) //if either has an issue return empty vectors
			response=new FeaturedTabResponse(Response.STATUS_FAILED_GENERIC,new Vector<Book>(), new Vector<Book>());
		else
			response=new FeaturedTabResponse(Response.STATUS_GOOD,bookArrayListToVector(active),bookArrayListToVector(recent));
	}
	
	/**
	 * convert a array list of books into a vector of books
	 * 
	 * @param l -- the list to be converted
	 * @return Vector<Book>
	 */
	public Vector<Book> bookArrayListToVector(ArrayList<Book> l) {
		Vector<Book> v = new Vector<Book>();
		for(int i=0;i<l.size();i++) {
			v.add(l.get(i));
		}
		return v;
	}
	
	/**
	 * Converts a ArrayList of Users into a Vector of users
	 * 
	 * @param l -- the list that you wish to convert
	 * @return Vector<User>
	 */
	public Vector<User> userArrayListToVector(ArrayList<User> l) {
		Vector<User> v = new Vector<User>();
		for(int i=0;i<l.size();i++) {
			v.add(l.get(i));
		}
		return v;
	}
	
	/**
	 * Converts an arrayList of MessageThreads into a Vector of messageThreads
	 * 
	 * @param l -- The arraylist you wish to convert
	 * @return Vector<MessageThread>
	 */
	public Vector<MessageThread> messageThreadArrayListToVector(ArrayList<MessageThread> l) {
		Vector<MessageThread> v = new Vector<MessageThread>();
		for(int i=0;i<l.size();i++) {
			v.add(l.get(i));
		}
		return v;
	}
	
	/**
	 * Converts an arrayList of Messages into a Vector of Messages
	 * 
	 * @param l -- The arrayList of messages
	 * @return Vector<Message>
	 */
	public Vector<Message> messageArrayListToVector(ArrayList<Message> l) {
		Vector<Message> v = new Vector<Message>();
		for(int i=0;i<l.size();i++) {
			v.add(l.get(i));
		}
		return v;
	}
	
	/**
	 * handles the book search request and set the response appropriately 
	 */
	private void handleBookSearch() {
		int start=((BookSearchRequest)request).getSearchPageSize()*(((BookSearchRequest)request).getSearchPageNumber()); //get the start and end numbers of books
		int end=start+((BookSearchRequest)request).getSearchPageSize();
		ArrayList<Book> results= Server.manager.bookSearch(((BookSearchRequest)request).getTitle(),((BookSearchRequest)request).getIsbn(), ((BookSearchRequest)request).getAuthor(),((BookSearchRequest)request).getSummary(),((BookSearchRequest)request).getPublisher(), ((BookSearchRequest)request).getOmniSearch(),((BookSearchRequest)request).getStatus(),((BookSearchRequest)request).getYear(),start,end);
		if(results!=null)
			response=new BookSearchResponse(Response.STATUS_GOOD,bookArrayListToVector(results));
		else
			response=new BookSearchResponse(Response.STATUS_FAILED_GENERIC,null);
	}
	
	/**
	 * handles a book Info response and set the response appropriately 
	 */
	private void handleBookInfo() {
		Book temp=Server.manager.getBookInfo(((BookInfoRequest)request).getBid());
		if(temp!=null) {
			boolean b = temp.getOwnerID() == user.getUID(); // check if the book is owned by the requesting user
			response = new BookInfoResponse(Response.STATUS_GOOD, temp, b);
		}
		else
			response = new BookInfoResponse(Response.STATUS_FAILED_GENERIC, temp, false);
	}
	
	/**
	 * handles the profile tab request and set the response appropriately 
	 */
	private void handleProfileTab() {
		ArrayList<Book> usersBooks = Server.manager.usersBooks(user.getUID());
		ArrayList<Book> checkedOut = Server.manager.checkedOutBooks(user.getUID());
		int numMessages = Server.manager.unReadMessages(user.getUID());
		if((usersBooks!=null&&checkedOut!=null)&&numMessages!=-1)
			response = new ProfileTabResponse(Response.STATUS_GOOD,bookArrayListToVector(usersBooks),bookArrayListToVector(checkedOut),numMessages,0); //TODO Change ProfileStats to be actual stats
		else {
			response = new ProfileTabResponse(Response.STATUS_FAILED_GENERIC,null,null,0,0); //TODO Change ProfileStats to be actual stats
		}
	}
	
	/**
	 * handles the ISBN lookup request and set the response appropriately 
	 */
	private void handleISBNLookup() {
		response = new IsbnLookUpResponse(Response.STATUS_GOOD,Server.manager.isbnLookUp(((IsbnLookUpRequest)request).getIsbn()));
	}
	
	
	/**
	 * handles the book creation request and set the response appropriately 
	 */
	private void handleBookCreation() {
		Book temp = ((CreateBookRequest)request).getBook();
		temp.setOwnerID(user.getUID()); // set the owner ID to the current user
		if(Server.manager.createBook(temp)) {
			response = new CreateBookResponse(Response.STATUS_GOOD);
		}
		else {
			response = new CreateBookResponse(Response.STATUS_FAILED_GENERIC);
		}
	}
	
	/**
	 * handles the Admin panel request and set the response appropriately 
	 */
	private void handleAdminPanel() {
		String message = Server.manager.getServerMessage();
		if(message==null) {
			response = new AdminPanelResponse(Response.STATUS_FAILED_GENERIC);
			return;
		}	
		if(user.getStatus()==User.Permission.ADMINISTRATOR) {
			response = new AdminPanelResponse(Response.STATUS_GOOD,Server.config.passwordRequired(),message);
		}
		else
			response=new AdminPanelResponse(AdminPanelResponse.STATUS_FAILED_USER_NOT_ADMIN);
	}
	
	/**
	 * handles the mailbox message request and set the response appropriately 
	 */
	private void handleMessages() {
		int start=(((MailboxMessagesRequest)request).getMailPageNumber())*((MailboxMessagesRequest)request).getMailPageSize();
		int end=start+((MailboxMessagesRequest)request).getMailPageSize();
		ArrayList<MessageThread> threads = Server.manager.getMessageThreads(user, start, end);
		if(threads!=null)
			response=new MailboxMessagesResponse(Response.STATUS_GOOD,messageThreadArrayListToVector(threads));
		else
			response=new MailboxMessagesResponse(Response.STATUS_FAILED_GENERIC,null);
	}
	
	/**
	 * handles the send message request and set the response appropriately 
	 */
	private void handleSendMessage() {
		boolean b=false;
		MessageThread temp = ((SendMessageRequest)request).getMessageThread();
		Message message = ((SendMessageRequest)request).getMessage();
		int messageID;
		switch(((SendMessageRequest)request).getAction()) {
			//This is just a reply to a pre-existing message.
			case SendMessageRequest.APPEND_MESSAGE:
				b=Server.manager.sendMessage(((SendMessageRequest)request).getMessage());
				break;
			//This is a new book Request
			case SendMessageRequest.BOOK_REQUEST:
				temp.setUser1(user.getUID()); // userID to be current user
				message.setNeedsApproval(true); // set the request as needing approval (used with the Accepting or denying)
				b=Server.manager.sendNewMessage(message, temp);
				if(b) {
					b=Server.manager.changedBookStatus(temp.getBid(), Book.BookStatus.PENDING, -1);
				}
				break;
			//this is a response accepting a book request
			case SendMessageRequest.RESPOND_ACCEPT:
				messageID=Server.manager.getFirstMessageID(message.getThreadId()); // find the first message to change the satus of is pending
				if(messageID!=-1) {
					b=Server.manager.setPendingStatus(messageID, false); // change request status
					if(b) {
						b=Server.manager.sendMessage(message); // send the message
						if(b) {
							b=Server.manager.changedBookStatus(temp.getBid(), Book.BookStatus.CHECKED_OUT, user.getUID()); // change book status
						}
					}
				}
				break;
			//This response is denying a book request
			case SendMessageRequest.RESPOND_DENY:
				messageID=Server.manager.getFirstMessageID(message.getThreadId()); // find the first message to change the satus of is pending
				if(messageID!=-1) {
					b=Server.manager.setPendingStatus(messageID, false); // change request status
					if(b) {
						b=Server.manager.sendMessage(((SendMessageRequest)request).getMessage()); // send the message
						if(b) {
							b=Server.manager.changedBookStatus(temp.getBid(), Book.BookStatus.AVAILABLE, -1); // change book status
						}
					}
				}
				break;
		}
		//sets an appropriate response
		if(b) {
			response=new SendMessageResponse(Response.STATUS_GOOD);
		}
		else {
			response=new SendMessageResponse(Response.STATUS_FAILED_GENERIC);
		}
	}
	
	/**
	 * handles logout requests and sets response appropriately 
	 */
	private void handleLogout() {
		Server.manager.logout(request.getAccessKey());
		response=new LogoutResponse(Response.STATUS_GOOD);
	}
	
	/**
	 * handles server ping requests and sets response appropriately 
	 */
	private void handlePing() {
		response=new ServerPingResponse(Response.STATUS_GOOD);
	}
	
	/**
	 * handles account info request and sets response appropriately 
	 */
	private void handleAccountInfo() {
		response=new AccountInfoResponse(Response.STATUS_GOOD,user);
	}
	
	/**
	 * handles account update requests and sets response appropriately 
	 */
	private void handleAccountUpdate() {
		//user wishes to delete account
		if(((AccountUpdateRequest)request).getAction()==AccountUpdateRequest.ACTION_DELETE) {
			if(Server.manager.removeUser(user,request.getAccessKey())){
				response=new AccountUpdateResponse(Response.STATUS_GOOD);
			}
			else
				response=new AccountUpdateResponse(Response.STATUS_FAILED_GENERIC);
		}
		//user wishes to update the information in the account
		else if(((AccountUpdateRequest)request).getAction()==AccountUpdateRequest.ACTION_UPDATE) {
			User tmp=((AccountUpdateRequest)request).getUser();
			if(user.getUID()==tmp.getUID()) { // make user is the same as is trying to be edited
				tmp.setStatus(user.getStatus()); // prevent an upgrade in permission levels
				tmp=Server.manager.updateUser(tmp); 
				if(tmp!=null) {
					user=tmp;
					response=new AccountUpdateResponse(Response.STATUS_GOOD);
				}
				else
					response=new AccountUpdateResponse(Response.STATUS_FAILED_GENERIC);
			}
			response=new AccountUpdateResponse(Response.STATUS_FAILED_GENERIC);
		}
	}
	
	/**
	 * handles ModeratorPanel requests and sets response appropriately 
	 */
	private void handleModeratorPanel() {
		//make sure the user has the right permission level
		if(user.getStatus()==Permission.MODERATOR||user.getStatus()==Permission.ADMINISTRATOR) {
			ArrayList<User> users=Server.manager.getUsers(0,20);//TODO get page values for these
			ArrayList<Book> books=Server.manager.getBooks(0,20);
			if(users==null||books==null) {
				response = new ModeratorPanelResponse(Response.STATUS_FAILED_GENERIC);
			}
			else {
				response = new ModeratorPanelResponse(Response.STATUS_GOOD,userArrayListToVector(users),bookArrayListToVector(books));
			}
		}
		else {
			response = new ModeratorPanelResponse(ModeratorPanelResponse.STATUS_FAILED_USER_NOT_MODERATOR);
		}
	}
	
	/**
	 * handles Moderator Action requests and sets response appropriately 
	 */
	private void handleModeratorAction() {
		boolean sucess=false;
		//verify user has the right permission
		if(user.getStatus()==Permission.MODERATOR||user.getStatus()==Permission.ADMINISTRATOR) {
			//delete a book
			if(((ModeratorActionRequest) request).getAction()==ModeratorActionRequest.ACTION_DELETE_BOOK) {
				sucess=Server.manager.removeBook(((ModeratorActionRequest)request).getElementID());
				
			}
			//delete a user
			else if(((ModeratorActionRequest) request).getAction()==ModeratorActionRequest.ACTION_DELETE_USER) {
				sucess=Server.manager.removeUser(((ModeratorActionRequest)request).getElementID());
			}
			if(sucess){
				response=new ModeratorActionResponse(Response.STATUS_GOOD);
			}
			else
				response=new ModeratorActionResponse(Response.STATUS_FAILED_GENERIC);
		}
		else {
			response = new ModeratorActionResponse(ModeratorActionResponse.STATUS_FAILED_USER_NOT_MODERATOR);
		}
	}
	
	/**
	 * handles picture requests and sets response appropriately 
	 */
	private void handlePictureRequest() {
		Book b= Server.manager.getBookInfo(((PictureRequest)request).getBid());
		if(b==null) {
			response = new PictureResponse(Response.STATUS_FAILED_GENERIC);
		}
		else {
			response=new PictureResponse(Response.STATUS_GOOD,((PictureRequest)request).getBid(),b.getISBN(),b.getPicture());
		}
	}
	
	/**
	 * handles Admin Action requests and sets response appropriately 
	 */
	private void handleAdminAction() {
		//make sure user is Administrator
		if(user.getStatus()==User.Permission.ADMINISTRATOR) {
			//disactivate the server password
			switch(((AdminActionRequest)request).getAciton()) {
				case AdminActionRequest.ACTION_DISACTIVATE_PASSWORD:
					Server.config.setPasswordRequired(0);
					Server.buildXML();
					break;
				//Set and activate the server password
				case AdminActionRequest.ACTION_SET_PASSWORD:
					if(Server.manager.setServerPassword(((AdminActionRequest)request).getText())) {
						response = new AdminActionResponse(Response.STATUS_GOOD);
						Server.config.setPasswordRequired(1);
					}
					else
						response = new AdminActionResponse(Response.STATUS_FAILED_GENERIC);
					break;
				//set the server message
				case AdminActionRequest.ACTION_SET_SERVER_MESSAGE:
					if(Server.manager.setServerMessage(((AdminActionRequest)request).getText()))
						response = new AdminActionResponse(Response.STATUS_GOOD);
					else
						response = new AdminActionResponse(Response.STATUS_FAILED_GENERIC);
					break;
				default:
					response = new AdminActionResponse(Response.STATUS_FAILED_GENERIC);
			}
		}
		else
			response=new AdminActionResponse(AdminActionResponse.STATUS_FAILED_USER_NOT_ADMIN);
	}
	
	/**
	 * handles ServerInfo requests and sets response appropriately
	 */
	private void handleServerInfo() {
		String message=Server.manager.getServerMessage();
		if(message==null) {
			response=new ServerInfoResponse(Response.STATUS_FAILED_GENERIC);
		}
		else {
			response=new ServerInfoResponse(Response.STATUS_GOOD,"",message); //TODO figure out organization
		}
		
	}
	
	/**
	 * handles Thread Status change requests and sets response appropriately
	 */
	private void changeThreadStatus() {
		switch(((ChangeMessageStatusRequest)request).getAction()) {
			case ChangeMessageStatusRequest.ACTION_MARK_READ:
				Server.manager.setThreadRead(true, ((ChangeMessageStatusRequest)request).getThreadId());
			case ChangeMessageStatusRequest.ACTION_MARK_UNREAD:
				Server.manager.setThreadRead(false, ((ChangeMessageStatusRequest)request).getThreadId());
		}
	}
	
	/**
	 * handles Thread messages request requests and sets response appropriately
	 */
	private void handleThreadMessages () {
		MessageThread thread=((GetThreadMessagesRequest)request).getMessageThread();
		int threadID=thread.getThreadId();
		ArrayList<Message> temp = Server.manager.getMessages(threadID);
		if(temp==null)
			response=new GetThreadMessageResponse(Response.STATUS_FAILED_GENERIC);
		else {
			Message first=temp.get(0);
			if(thread.getUser1()==user.getUID()&&thread.getUser1()!=thread.getUser2())
				first.setNeedsApproval(false);
			response=new GetThreadMessageResponse(Response.STATUS_GOOD,messageArrayListToVector(temp));
		}
	}
	
	/**
	 * handles EditBook requests and sets response appropriately
	 */
	private void handleEditBook() {
		boolean successful=false;
		Book b = ((EditBookRequest)request).getBook();
		if(b.getOwnerID()==user.getUID()) { // make sure book is owned by the owner
			b.setOwnerID(user.getUID());
			Book a =Server.manager.getBookInfo(b.getBID());
			if(a!=null) { //verify the book exists in the database
				if(Server.manager.editBook(b)) {
					if(a.getBookStatus()!=b.getBookStatus()) { // change the checkout status to the approriate value
						if(b.getBookStatus()==Book.BookStatus.CHECKED_OUT) 
							Server.manager.changedBookStatus(b.getBID(), b.getBookStatus(), user.getUID()); //check out the book to the owner
						else
							Server.manager.changedBookStatus(b.getBID(), b.getBookStatus(), -1);
					}
					successful=true;
				}
			}
			
		}
		if(successful) {
			response = new EditBookResponse(Response.STATUS_GOOD);
		}
		else {
			response = new EditBookResponse(Response.STATUS_FAILED_GENERIC);
		}
	}
}
